package net.discard.controller;

import com.alibaba.fastjson.JSONObject;
import net.discard.dao.PartnerRepository;
import net.discard.model.Activity;
import net.discard.model.Partner;
import net.discard.model.User;
import net.discard.model.domian.ResponseVo;
import net.discard.model.vo.ActivityVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: Discard
 * @Date: 2021/2/20 3:02 下午
 */
@RestController
@RequestMapping("/partner")
public class PartnerController {

    @Autowired
    private PartnerRepository partnerRepository;

    @GetMapping(value = "/list/{userId}")
    public String getPartnerList(@PathVariable long userId) {
        List<Partner> list = partnerRepository.findByUserId(userId);
        return new ResponseVo(list).toString();
    }

    @PostMapping(value = "/add")
    public String userRegister(@RequestBody JSONObject partnerInfo) {
        partnerRepository.save(new Partner(partnerInfo.getJSONObject("res")));
        return new ResponseVo().toString();
    }
}
